<?php

use Faker\Factory as Faker;
use App\Models\WechatUserSession;
use App\Repositories\WechatUserSessionRepository;

trait MakeWechatUserSessionTrait
{
    /**
     * Create fake instance of WechatUserSession and save it in database
     *
     * @param array $wechatUserSessionFields
     * @return WechatUserSession
     */
    public function makeWechatUserSession($wechatUserSessionFields = [])
    {
        /** @var WechatUserSessionRepository $wechatUserSessionRepo */
        $wechatUserSessionRepo = App::make(WechatUserSessionRepository::class);
        $theme = $this->fakeWechatUserSessionData($wechatUserSessionFields);
        return $wechatUserSessionRepo->create($theme);
    }

    /**
     * Get fake instance of WechatUserSession
     *
     * @param array $wechatUserSessionFields
     * @return WechatUserSession
     */
    public function fakeWechatUserSession($wechatUserSessionFields = [])
    {
        return new WechatUserSession($this->fakeWechatUserSessionData($wechatUserSessionFields));
    }

    /**
     * Get fake data of WechatUserSession
     *
     * @param array $postFields
     * @return array
     */
    public function fakeWechatUserSessionData($wechatUserSessionFields = [])
    {
        $fake = Faker::create();

        return array_merge([
            'openid' => $fake->word,
            'unionid' => $fake->word,
            'session_key' => $fake->word,
            'status' => $fake->randomDigitNotNull,
            'updated_at' => $fake->word,
            'created_at' => $fake->word
        ], $wechatUserSessionFields);
    }
}
